package com.lc.zpyh.view;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.lc.zpyh.R;

import butterknife.ButterKnife;
import cn.jzvd.Jzvd;
import cn.jzvd.JzvdStd;

public class LooKVideoDialog  extends Dialog implements View.OnClickListener {

    private Context context;
    private ImageView img_close;
    private String url;
    private String title;
    private TextView tv_title;

    public LooKVideoDialog(Context context, String url,String title) {
        super(context, R.style.dialog);
        this.context = context;
        this.url = url;
        this.title = title;

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);

        Window window = getWindow();
        window.setGravity(Gravity.CENTER); // 此处可以设置dialog显示的位置为居中
//        window.setWindowAnimations(R.style.bottom_menu_animation); // 添加动画效果
        setContentView(R.layout.dialog_lookvideo);
        WindowManager windowManager = ((Activity) context).getWindowManager();
//        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        getWindow().setAttributes(lp);
        setCanceledOnTouchOutside(false);// 点击Dialog外部消失



        initView();


    }
    private void initView() {
        tv_title = findViewById(R.id.tv_title);

        img_close = findViewById(R.id.img_close);
         tv_title.setText(title);
        img_close.setOnClickListener(this);
        JzvdStd jzvdStd = (JzvdStd) findViewById(R.id.jz_video);
        jzvdStd.setUp(url, "");
        jzvdStd.posterImageView.setImageResource(R.mipmap.zhanweiicon01);



    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {

            case R.id.img_close:


                dismiss();
                break;



            default:
                break;
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        Jzvd.releaseAllVideos();
    }
}
